package com.zzuli.xyd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzuli.xyd.pojo.Userinfo;
import org.apache.ibatis.annotations.*;

import java.lang.reflect.Member;
import java.util.List;

/**
 * @auther pony
 * @create 2022-07-06 10:24
 */
@Mapper
public interface UserMapper extends BaseMapper<Userinfo> {
    //映射
    @Results(id="userinfoMaps", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "address", column = "address"),
            @Result(property = "phone", column = "phone")
    })
    @Select("<script>" +
            "select id, username, gender, address, phone from userinfo " +
            "<where>" +
            "<if test='keyword !=null'>" +
            " username like CONCAT('%',#{keyword},'%') or " +
            " gender like CONCAT('%',#{keyword},'%') or " +
            " address like CONCAT('%',#{keyword},'%') or " +
            " phone like CONCAT('%',#{keyword},'%') " +
            "</if>" +
            "</where>"+
            " limit #{pageIndex},#{pageSize}" +
            "</script>")
    public List<Userinfo> getUserinfoPage(@Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize, @Param("keyword") String keyword);

    @Select("<script>" +
            "select Count(*) from userinfo " +
            "<where>" +
            "<if test='keyword != null'>" +
            " username like CONCAT('%',#{keyword},'%') or" +
            " gender like CONCAT('%',#{keyword},'%') or " +
            " address like CONCAT('%',#{keyword},'%') or " +
            " phone like CONCAT('%',#{keyword},'%') " +
            "</if>" +
            "</where>" +
            "</script>")
    public Integer getTotal(@Param("keyword") String keyword);
}
